//
//  BidResultViewController.m
//  KKZ
//
//  Created by  on 11-7-24.
//  Copyright 2011年 Tsinghua University. All rights reserved.
//

#import "BidResultViewController.h"
#import "UIViewController+BarItem.h"
#import "CheckoutViewController.h"

@implementation BidResultViewController

@synthesize mainTableView;
@synthesize chooseSeatButton;
@synthesize goToCheckButton;
@synthesize movieNameLabel;
@synthesize titleName;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (id)initWithTitle:(NSString *)titlename
{
    self = [super init];
    if (self) {
        self.titleName = titlename;
    }
    
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)pop
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"恭喜您竞价成功！" message:@"请您点击座位按钮选择座位，然后点击付款进入付款页面" delegate:nil cancelButtonTitle:@"好的，我知道了" otherButtonTitles:nil, nil];
    [alert show];
    [alert release];
    self.mainTableView.separatorColor = [UIColor darkGrayColor];
    self.mainTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.mainTableView.backgroundColor = [UIColor clearColor];
    
    self.movieNameLabel.text = self.titleName;
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
    
    [self addTitleToNavigationBar:@"匹配结果"];
    [self createBarItemOn:kNavBarItemSideLeft frame:kNavBarLeftItemFrame title:@"返回" target:self action:@selector(pop)];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark -
#pragma mark - Table View Delegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"CellIdentifier";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier] autorelease];
    }
    
    [cell.textLabel setFont:[UIFont systemFontOfSize:14.0f]];
    [cell.detailTextLabel setFont:[UIFont systemFontOfSize:16.0f]];
    
    if (indexPath.row == 0) {
        cell.textLabel.text = @"购买票数";
        cell.detailTextLabel.text = @"1张";
    }
    else if (indexPath.row == 1) {
        cell.textLabel.text = @"影院信息";
        cell.detailTextLabel.text = @"中关村美嘉";
        
        /*
        UIButton *mapButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [mapButton setFrame:CGRectMake(0, 0, 30, 30)];
        [mapButton setBackgroundImage:[UIImage imageNamed:@"mapbutton.png"] forState:UIControlStateNormal];
        
        cell.accessoryView = mapButton;
         */
        
    }
    else if (indexPath.row == 2) {
        cell.textLabel.text = @"开场时间";
        cell.detailTextLabel.text = @"18:30";
    }
    else if (indexPath.row == 3) {
        cell.textLabel.text = @"成交价格";
        cell.detailTextLabel.text = @"50元";
    }
    
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (IBAction)lastStep
{
    CheckoutViewController *viewController = [[CheckoutViewController alloc] initWithTitle:self.titleName];
    [self.navigationController pushViewController:viewController animated:YES];
    [viewController release];
}

@end
